<template>
  <div class="content_box">
    <div class="main-box">
      <p class="main-title">修改办案人</p>
      <p class="main-text">
        注：取保时间一旦修改不可修改，日期请与文书一直后续可案件延期申请。
      </p>
      <el-form :model="form" :rules="rules" ref="updateForms">
        <el-form-item label="选择办案人" label-width="120px" prop="admin_id">
          <el-select
            v-model="form.admin_id"
            placeholder="请选择办案人"
            size="large"
            style="width: 90%"
          >
            <el-option
              v-for="item in list"
              :key="item.admin_id"
              :label="item.nickname"
              :value="item.admin_id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button
          :loading="loading"
          :disabled="loading"
          type="primary"
          @click="submit"
        >
          提交
        </el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted, defineProps,defineEmits } from "vue";
import { ElNotification } from "element-plus";
import { saveBailPolice, policeList } from "@/api/bond/pay";

const props = defineProps({
  bailId: {
    type: Number,
  },
  id: {
    type: Number,
  },
});

let form = ref({
  process_id: props.id,
  admin_id: null,
});

const emit = defineEmits(['closeDrawer']);

onMounted(() => {
  getPoliceList();
});

// 获取办案人列表
let list = ref([]);
const getPoliceList = async () => {
  await policeList({ process_id: form.value.process_id }).then((res) => {
    if (res.code == 1) {
      list.value = res.data;
    }
  });
};

/*=====提交=====*/
const updateForms = ref();
let loading = ref(false);
const rules = reactive({
  admin_id: [{ required: true, message: "请选择办案人", trigger: "change" }],
});

const submit = async () => {
  console.log(form.value);
  await updateForms.value.validate();
  loading.value = true;

  await saveBailPolice(form.value).then((res) => {
    if (res.code == 1) {
      ElNotification({ message: res.msg, type: "success" });
      close()
    } else {
      loading.value = false;
      ElNotification.error(res.msg);
    }
  });
};

// 关闭
const close=()=>{
  form.value.admin_id = ''
  loading.value = false
  setTimeout(() => {
    updateForms.value.clearValidate();
  }, 500);
  
  emit("closeDrawer");
}
</script>
<style scoped lang="scss">
.dialog-footer {
  margin-top:50px;
  text-align: center;
}
.main-box{
  min-height: auto;
}
.main-text{
  margin:20px 0 47px 0;
  font-size: 14px;
  color: #323C4F;
}
</style>
  